<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的报名 | 爱心志愿者平台</title>
    <!-- 引入Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- 引入Font Awesome图标 -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- 配置Tailwind主题 -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#4F46E5', // 主色调：深紫色
                        secondary: '#10B981', // 辅助色：绿色
                        accent: '#F59E0B', // 强调色：橙色
                        neutral: {
                            100: '#F3F4F6',
                            200: '#E5E7EB',
                            300: '#D1D5DB',
                            700: '#374151',
                            800: '#1F2937',
                            900: '#111827',
                        }
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <!-- 自定义工具类 -->
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .table-shadow {
                box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            }
            .btn-primary {
                @apply bg-primary text-white font-medium py-2 px-4 rounded-lg transition-all duration-300 hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-primary/50 focus:ring-offset-2;
            }
            .btn-danger {
                @apply bg-red-500 text-white font-medium py-2 px-4 rounded-lg transition-all duration-300 hover:bg-red-600 focus:outline-none focus:ring-2 focus:ring-red-500/50 focus:ring-offset-2;
            }
            .btn-outline {
                @apply border border-neutral-300 text-neutral-700 font-medium py-2 px-4 rounded-lg transition-all duration-300 hover:bg-neutral-50 focus:outline-none focus:ring-2 focus:ring-neutral-300/50 focus:ring-offset-2;
            }
            .status-badge {
                @apply inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium;
            }
        }
    </style>
</head>
<body class="font-inter bg-neutral-100 text-neutral-800 min-h-screen flex flex-col">
<!-- 顶部导航栏 -->
<header class="bg-white shadow-md sticky top-0 z-50 transition-all duration-300">
    <div class="container mx-auto px-4 sm:px-6 lg:px-8">
        <div class="flex justify-between items-center h-16">
            <div class="flex items-center">
                <a href="/activities/home" class="flex items-center space-x-2">
                    <i class="fa fa-heart text-primary text-2xl"></i>
                    <span class="text-xl font-bold text-neutral-800">爱心志愿者平台</span>
                </a>
            </div>
            <nav class="hidden md:flex space-x-8">
                <a href="/activities/home" class="text-neutral-700 hover:text-primary transition-colors">首页</a>
                <a href="/activities/list" class="text-neutral-700 hover:text-primary transition-colors">活动列表</a>
                <a href="/user/registrations" class="text-primary font-medium border-b-2 border-primary">我的报名</a>
                <a href="#" class="text-neutral-700 hover:text-primary transition-colors">个人中心</a>
            </nav>
            <div class="flex items-center space-x-4">
                <div class="relative group">
                    <button class="flex items-center space-x-2 focus:outline-none">
                        <img src="https://picsum.photos/id/1005/40/40" alt="用户头像" class="w-8 h-8 rounded-full object-cover border-2 border-white shadow-sm">
                        <span class="hidden md:inline text-sm font-medium">志愿者</span>
                        <i class="fa fa-chevron-down text-xs text-neutral-500"></i>
                    </button>
                    <div class="absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg py-1 z-50 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 origin-top-right transform group-hover:scale-100 scale-95">
                        <a href="#" class="block px-4 py-2 text-sm text-neutral-700 hover:bg-neutral-100">个人信息</a>
                        <a href="#" class="block px-4 py-2 text-sm text-neutral-700 hover:bg-neutral-100">我的报名</a>
                        <a href="#" class="block px-4 py-2 text-sm text-neutral-700 hover:bg-neutral-100">志愿服务时长</a>
                        <div class="border-t border-neutral-200 my-1"></div>
                        <a href="#" class="block px-4 py-2 text-sm text-red-600 hover:bg-neutral-100">退出登录</a>
                    </div>
                </div>
                <button class="md:hidden text-neutral-700" id="mobile-menu-button">
                    <i class="fa fa-bars text-xl"></i>
                </button>
            </div>
        </div>
    </div>

    <!-- 移动端菜单 -->
    <div class="md:hidden hidden bg-white border-t" id="mobile-menu">
        <div class="container mx-auto px-4 py-3 space-y-3">
            <a href="/activities/home" class="block py-2 text-neutral-700 hover:text-primary transition-colors">首页</a>
            <a href="/activities/list" class="block py-2 text-neutral-700 hover:text-primary transition-colors">活动列表</a>
            <a href="/user/registrations" class="block py-2 text-primary font-medium border-l-4 border-primary pl-2">我的报名</a>
            <a href="#" class="block py-2 text-neutral-700 hover:text-primary transition-colors">个人中心</a>
            <div class="border-t border-neutral-200 my-2"></div>
            <a href="#" class="block py-2 text-sm text-red-600 hover:bg-neutral-100">退出登录</a>
        </div>
    </div>
</header>

<!-- 主要内容区 -->
<main class="flex-grow container mx-auto px-4 sm:px-6 lg:px-8 py-8">
    <!-- 页面标题 -->
    <div class="mb-8">
        <h1 class="text-[clamp(1.8rem,4vw,2.5rem)] font-bold text-neutral-800">
            <i class="fa fa-list-alt text-primary mr-2"></i>我的活动报名
        </h1>
        <p class="text-neutral-600 mt-1">查看您已报名的志愿活动，随时了解活动状态</p>
    </div>

    <!-- 筛选和搜索 -->
    <div class="bg-white rounded-xl p-4 mb-6 shadow-sm">
        <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
            <div class="flex flex-wrap gap-3">
                <button class="px-4 py-2 bg-primary text-white rounded-lg text-sm font-medium">
                    全部状态
                </button>
                <button class="px-4 py-2 bg-white text-neutral-700 rounded-lg text-sm font-medium hover:bg-neutral-50 transition-colors">
                    已确认
                </button>
                <button class="px-4 py-2 bg-white text-neutral-700 rounded-lg text-sm font-medium hover:bg-neutral-50 transition-colors">
                    待审核
                </button>
                <button class="px-4 py-2 bg-white text-neutral-700 rounded-lg text-sm font-medium hover:bg-neutral-50 transition-colors">
                    已取消
                </button>
            </div>
            <div class="relative w-full md:w-64">
                <input type="text" placeholder="搜索活动..."
                       class="w-full pl-10 pr-4 py-2 rounded-lg border border-neutral-300 focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all">
                <i class="fa fa-search absolute left-3 top-1/2 -translate-y-1/2 text-neutral-400"></i>
            </div>
        </div>
    </div>

    <!-- 报名列表 -->
    <div class="bg-white rounded-xl overflow-hidden table-shadow mb-8">
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead>
                <tr class="bg-neutral-50 text-left text-neutral-700 text-sm font-medium">
                    <th class="px-6 py-4 whitespace-nowrap">
                        <div class="flex items-center">
                            <i class="fa fa-hashtag mr-2"></i>报名编号
                        </div>
                    </th>
                    <th class="px-6 py-4 whitespace-nowrap">
                        <div class="flex items-center">
                            <i class="fa fa-calendar-check-o mr-2"></i>活动信息
                        </div>
                    </th>
                    <th class="px-6 py-4 whitespace-nowrap">
                        <div class="flex items-center">
                            <i class="fa fa-clock-o mr-2"></i>报名时间
                        </div>
                    </th>
                    <th class="px-6 py-4 whitespace-nowrap">
                        <div class="flex items-center">
                            <i class="fa fa-info-circle mr-2"></i>状态
                        </div>
                    </th>
                    <th class="px-6 py-4 whitespace-nowrap text-right">
                        <div class="flex items-center justify-end">
                            <i class="fa fa-cog mr-2"></i>操作
                        </div>
                    </th>
                </tr>
                </thead>
                <tbody class="divide-y divide-neutral-200">
                <c:forEach items="${registrations}" var="registration">
                    <tr class="hover:bg-neutral-50 transition-colors">
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-neutral-700">
                            <div class="font-medium">#${registration.registrationId}</div>
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex items-center">
                                <img src="${registration.activity.coverImage}" alt="${registration.activity.title}" class="w-12 h-12 rounded-lg object-cover mr-4">
                                <div>
                                    <div class="font-medium text-neutral-800">${registration.activity.title}</div>
                                    <div class="text-sm text-neutral-500">
                                        <i class="fa fa-map-marker mr-1"></i>${registration.activity.location}
                                    </div>
                                    <div class="text-sm text-neutral-500">
                                        <i class="fa fa-calendar mr-1"></i>
                                        <fmt:formatDate value="${registration.activity.startTime}" pattern="yyyy-MM-dd" />
                                        -
                                        <fmt:formatDate value="${registration.activity.endTime}" pattern="yyyy-MM-dd" />
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-sm text-neutral-700">
                            <fmt:formatDate value="${registration.registrationTime}" pattern="yyyy-MM-dd HH:mm:ss" />
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <c:choose>
                                <c:when test="${registration.status == '已确认'}">
                                            <span class="status-badge bg-green-100 text-green-800">
                                                <i class="fa fa-check-circle mr-1"></i>已确认
                                            </span>
                                </c:when>
                                <c:when test="${registration.status == '待审核'}">
                                            <span class="status-badge bg-yellow-100 text-yellow-800">
                                                <i class="fa fa-clock-o mr-1"></i>待审核
                                            </span>
                                </c:when>
                                <c:when test="${registration.status == '已取消'}">
                                            <span class="status-badge bg-red-100 text-red-800">
                                                <i class="fa fa-times-circle mr-1"></i>已取消
                                            </span>
                                </c:when>
                                <c:otherwise>
                                            <span class="status-badge bg-blue-100 text-blue-800">
                                                <i class="fa fa-info-circle mr-1"></i>${registration.status}
                                            </span>
                                </c:otherwise>
                            </c:choose>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                            <div class="flex items-center justify-end space-x-2">
                                <a href="#" class="btn-outline">
                                    <i class="fa fa-eye mr-1"></i>详情
                                </a>
                                <c:if test="${registration.status != '已取消'}">
                                    <a href="/registration/delete?id=${registration.registrationId}" class="btn-danger" onclick="return confirm('确定要取消报名吗？')">
                                        <i class="fa fa-times mr-1"></i>取消
                                    </a>
                                </c:if>
                            </div>
                        </td>
                    </tr>
                </c:forEach>

                <!-- 空状态 -->
                <c:if test="${empty registrations}">
                    <tr>
                        <td colspan="5" class="px-6 py-12 text-center">
                            <div class="flex flex-col items-center">
                                <i class="fa fa-calendar-times-o text-5xl text-neutral-300 mb-4"></i>
                                <h3 class="text-xl font-medium text-neutral-700 mb-2">暂无报名记录</h3>
                                <p class="text-neutral-500 mb-6 max-w-md">您还没有报名任何志愿活动，赶快去发现并参与感兴趣的活动吧！</p>
                                <a href="/activities/list" class="btn-primary">
                                    <i class="fa fa-search mr-1"></i>浏览活动
                                </a>
                            </div>
                        </td>
                    </tr>
                </c:if>
                </tbody>
            </table>
        </div>
    </div>

    <!-- 分页导航 -->
    <c:if test="${not empty registrations}">
        <div class="flex flex-col items-center">
            <nav class="flex items-center space-x-1">
                <!-- 首页和上一页 -->
                <c:if test="${currentPage > 1}">
                    <a href="${pageContext.request.contextPath}/user/registrations?page=1" class="px-3 py-1 rounded-md text-sm font-medium bg-white text-neutral-700 hover:bg-neutral-100 border border-neutral-200">
                        <i class="fa fa-angle-double-left"></i>
                    </a>
                    <a href="${pageContext.request.contextPath}/user/registrations?page=${currentPage - 1}" class="px-3 py-1 rounded-md text-sm font-medium bg-white text-neutral-700 hover:bg-neutral-100 border border-neutral-200">
                        <i class="fa fa-angle-left"></i>
                    </a>
                </c:if>

                <!-- 页码 -->
                <c:forEach begin="1" end="${totalPage}" var="i">
                    <c:choose>
                        <c:when test="${i == currentPage}">
                            <span class="px-3 py-1 rounded-md text-sm font-medium bg-primary text-white border border-primary">${i}</span>
                        </c:when>
                        <c:otherwise>
                            <a href="${pageContext.request.contextPath}/user/registrations?page=${i}" class="px-3 py-1 rounded-md text-sm font-medium bg-white text-neutral-700 hover:bg-neutral-100 border border-neutral-200">${i}</a>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>

                <!-- 下一页和末页 -->
                <c:if test="${currentPage < totalPage}">
                    <a href="${pageContext.request.contextPath}/user/registrations?page=${currentPage + 1}" class="px-3 py-1 rounded-md text-sm font-medium bg-white text-neutral-700 hover:bg-neutral-100 border border-neutral-200">
                        <i class="fa fa-angle-right"></i>
                    </a>
                    <a href="${pageContext.request.contextPath}/user/registrations?page=${totalPage}" class="px-3 py-1 rounded-md text-sm font-medium bg-white text-neutral-700 hover:bg-neutral-100 border border-neutral-200">
                        <i class="fa fa-angle-double-right"></i>
                    </a>
                </c:if>
            </nav>
            <p class="text-sm text-neutral-500 mt-2">
                共 ${totalPage} 页，当前第 ${currentPage} 页，${totalCount} 条记录
            </p>
        </div>
    </c:if>

    <!-- 底部操作按钮 -->
    <div class="mt-8 flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4">
        <a href="/activities/list" class="btn-outline flex items-center justify-center">
            <i class="fa fa-arrow-left mr-2"></i>返回活动列表
        </a>
        <a href="/activities/home" class="btn-outline flex items-center justify-center">
            <i class="fa fa-home mr-2"></i>返回首页
        </a>
    </div>
</main>

<!-- 页脚 -->
<footer class="bg-neutral-800 text-white py-12">
    <div class="container mx-auto px-4 sm:px-6 lg:px-8">
        <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
            <div>
                <div class="flex items-center mb-4">
                    <i class="fa fa-heart-o text-primary text-2xl mr-2"></i>
                    <span class="text-xl font-bold">爱心志愿者平台</span>
                </div>
                <p class="text-neutral-400 text-sm mb-4">
                    爱心志愿者平台是一个贵州性的志愿者服务平台，致力于为志愿者和志愿组织提供便捷、高效的服务对接。
                </p>
                <div class="flex space-x-4">
                    <a href="#" class="text-neutral-400 hover:text-primary transition-custom">
                        <i class="fa fa-weibo text-lg"></i>
                    </a>
                    <a href="#" class="text-neutral-400 hover:text-primary transition-custom">
                        <i class="fa fa-wechat text-lg"></i>
                    </a>
                    <a href="#" class="text-neutral-400 hover:text-primary transition-custom">
                        <i class="fa fa-qq text-lg"></i>
                    </a>
                </div>
            </div>

            <div>
                <h3 class="text-lg font-medium mb-4">志愿者服务</h3>
                <ul class="space-y-2 text-neutral-400">
                    <li><a href="#" class="hover:text-primary transition-custom">我要报名</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">服务项目</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">服务时长</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">志愿者培训</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">志愿者保险</a></li>
                </ul>
            </div>

            <div>
                <h3 class="text-lg font-medium mb-4">关于我们</h3>
                <ul class="space-y-2 text-neutral-400">
                    <li><a href="#" class="hover:text-primary transition-custom">平台介绍</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">新闻公告</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">联系我们</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">常见问题</a></li>
                    <li><a href="#" class="hover:text-primary transition-custom">意见反馈</a></li>
                </ul>
            </div>

            <div>
                <h3 class="text-lg font-medium mb-4">联系我们</h3>
                <ul class="space-y-2 text-neutral-400">
                    <li class="flex items-center">
                        <i class="fa fa-map-marker w-5 text-primary"></i>
                        <span>620志愿中心</span>
                    </li>
                    <li class="flex items-center">
                        <i class="fa fa-phone w-5 text-primary"></i>
                        <span>400-123-4567</span>
                    </li>
                    <li class="flex items-center">
                        <i class="fa fa-envelope-o w-5 text-primary"></i>
                        <span>service@volunteer.org.cn</span>
                    </li>
                    <li class="flex items-center">
                        <i class="fa fa-clock-o w-5 text-primary"></i>
                        <span>周一至周日 9:00-18:00</span>
                    </li>
                </ul>
            </div>
        </div>

        <div class="border-t border-neutral-700 mt-8 pt-8 text-center text-neutral-400 text-sm">
            <p>© 2025 爱心志愿者平台 版权所有 | 京ICP备12345678号</p>
        </div>
    </div>
</footer>

<!-- JavaScript -->
<script>
    // 移动端菜单切换
    document.getElementById('mobile-menu-button').addEventListener('click', function() {
        const mobileMenu = document.getElementById('mobile-menu');
        mobileMenu.classList.toggle('hidden');
    });

    // 滚动时改变导航栏样式
    window.addEventListener('scroll', function() {
        const header = document.querySelector('header');
        if (window.scrollY > 10) {
            header.classList.add('shadow-lg');
            header.classList.remove('shadow-md');
        } else {
            header.classList.remove('shadow-lg');
            header.classList.add('shadow-md');
        }
    });

    // 平滑滚动
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function(e) {
            e.preventDefault();
            const targetId = this.getAttribute('href');
            if (targetId === '#') return;

            const targetElement = document.querySelector(targetId);
            if (targetElement) {
                targetElement.scrollIntoView({
                    behavior: 'smooth'
                });
            }
        });
    });

    // 确认取消报名
    document.querySelectorAll('.btn-danger').forEach(button => {
        button.addEventListener('click', function(e) {
            if (!confirm('确定要取消报名吗？取消后可能无法再次报名该活动。')) {
                e.preventDefault();
            }
        });
    });
</script>
</body>
</html>